import request from '../utils/request'

// UI自动化脚本相关API

/**
 * 获取UI自动化脚本列表
 */
export function getUiAutomationScripts(params) {
  return request({
    url: '/api/v1/ui-automation/scripts',
    method: 'get',
    params
  })
}

/**
 * 获取UI自动化脚本详情
 */
export function getUiAutomationScript(id) {
  return request({
    url: `/api/v1/ui-automation/scripts/${id}`,
    method: 'get'
  })
}

/**
 * 创建UI自动化脚本
 */
export function createUiAutomationScript(data) {
  return request({
    url: '/api/v1/ui-automation/scripts',
    method: 'post',
    data
  })
}

/**
 * 更新UI自动化脚本
 */
export function updateUiAutomationScript(id, data) {
  return request({
    url: `/api/v1/ui-automation/scripts/${id}`,
    method: 'put',
    data
  })
}

/**
 * 删除UI自动化脚本
 */
export function deleteUiAutomationScript(id) {
  return request({
    url: `/api/v1/ui-automation/scripts/${id}`,
    method: 'delete'
  })
}

/**
 * 基于需求生成YAML脚本
 */
export function generateYamlScript(data) {
  return request({
    url: '/api/v1/ui-automation/scripts/generate-yaml',
    method: 'post',
    data
  })
}

/**
 * 验证YAML脚本格式
 */
export function validateYamlScript(yamlContent) {
  return request({
    url: '/api/v1/ui-automation/scripts/validate-yaml',
    method: 'post',
    data: yamlContent,
    headers: {
      'Content-Type': 'text/plain'
    }
  })
}

// UI自动化执行相关API

/**
 * 执行UI自动化脚本
 */
export function executeUiAutomationScript(scriptId, executionOptions = {}) {
  return request({
    url: `/api/v1/ui-automation/scripts/${scriptId}/execute`,
    method: 'post',
    data: executionOptions
  })
}

/**
 * 创建并执行UI自动化脚本
 */
export function createUiAutomationExecution(data) {
  return request({
    url: '/api/v1/ui-automation/executions',
    method: 'post',
    data
  })
}

/**
 * 获取UI自动化执行记录列表
 */
export function getUiAutomationExecutions(params) {
  return request({
    url: '/api/v1/ui-automation/executions',
    method: 'get',
    params
  })
}

/**
 * 获取UI自动化执行记录详情
 */
export function getUiAutomationExecution(id) {
  return request({
    url: `/api/v1/ui-automation/executions/${id}`,
    method: 'get'
  })
}

/**
 * 停止UI自动化执行
 */
export function stopUiAutomationExecution(id) {
  return request({
    url: `/api/v1/ui-automation/executions/${id}/stop`,
    method: 'post'
  })
}

// UI自动化批量执行相关API

/**
 * 创建并执行批量UI自动化任务
 */
export function createUiAutomationBatchExecution(data) {
  return request({
    url: '/api/v1/ui-automation/batch-executions',
    method: 'post',
    data
  })
}

/**
 * 获取批量执行记录列表
 */
export function getUiAutomationBatchExecutions(params) {
  return request({
    url: '/api/v1/ui-automation/batch-executions',
    method: 'get',
    params
  })
}

/**
 * 获取批量执行记录详情
 */
export function getUiAutomationBatchExecution(id) {
  return request({
    url: `/api/v1/ui-automation/batch-executions/${id}`,
    method: 'get'
  })
}

/**
 * 获取UI自动化统计信息
 */
export function getUiAutomationStats() {
  return request({
    url: '/api/v1/ui-automation/stats',
    method: 'get'
  })
}



/**
 * 查看报告文件
 */
export function viewUiAutomationReport(path) {
  return `/api/v1/ui-automation/reports/view?path=${encodeURIComponent(path)}`
}

/**
 * 下载报告文件
 */
export function downloadUiAutomationReport(path) {
  return `/api/v1/ui-automation/reports/download?path=${encodeURIComponent(path)}`
}
